//
//  CardViewController.m
//  Lextra Junior ueb IT
//
//  Created by Dirk Lieder on 30.05.11.
//  Copyright 2011 Phosphon. All rights reserved.
//

#import "WimmelViewController.h"
#import "AsyncImageView.h"
#import "WimmelOverlayViewController.h"

#import "Lextra_Engine.h"

@implementation WimmelViewController

@synthesize bigScrollView;
@synthesize wimmelOverlayViewController;
//__NGUYEN_HUY_SON__
@synthesize woerPre;
@synthesize imageView;
@synthesize navigationBar;
@synthesize tabbarControllerRoot;
//_____END_NGUYEN_HUY_SON
//__NGUYEN_HUY_SON__
 
NSMutableArray *wimmelArray;
NSDictionary *myArray;
AVAudioPlayer *audioPlayer;

NSString *myBild;
int myNumber;
//___SON____________________
NSDictionary *myPoindInfo;
float xPoind,yPoind;
CGPoint OffsetGloble;
//_______
bool overlayActive;
- (BOOL)isPadPortrait
{
    
    return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad
            && (self.interfaceOrientation == UIInterfaceOrientationPortrait
                || self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown));
}


- (BOOL)isPadLandscape
{
    return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad
            && (self.interfaceOrientation == UIInterfaceOrientationLandscapeRight
                || self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft));
}
- (void)setDelegatePlud:(id)new_delegate para:(NSArray *)para bIsParentThemmen:(BOOL)bIsThemmen{
    
    CGPoint newOffset;

	Delegate = new_delegate;
    myArray = (NSDictionary*)para;
	
    overlayActive = false;
    //__NGUYEN_HUY_SON__
    WimmelOverlayViewController *home ;
    //__END_NGUYEN_HUY_SON__
    if(self.wimmelOverlayViewController == nil){
        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 
        { 
            home = [[WimmelOverlayViewController alloc] initWithNibName:@"WimmelOverlayViewController-iPad" bundle:nil];
        }
        else
        {
            home = [[WimmelOverlayViewController alloc] initWithNibName:@"WimmelOverlayViewController" bundle:nil];
        }
        self.wimmelOverlayViewController = home;
        self.wimmelOverlayViewController.view.hidden = true;
        //[self.view insertSubview:home.view belowSubview:self.navigationViewController.view];
        [self.view addSubview:home.view];
        [home setDelegate:self];
        [home release];
    }
    self.wimmelOverlayViewController.view.hidden = true;

    if(bigScrollView){
        [[bigScrollView subviews] makeObjectsPerformSelector: @selector(removeFromSuperview)];
    }
    
    // process poinds...
    if(wimmelArray) [wimmelArray release];
    wimmelArray =  [[NSMutableArray alloc] init];
    
    UIImage *img;
    int myPoind = [[myArray objectForKey:@"wimmelnummer"] intValue];
    
   
    if([[myArray objectForKey:@"wimmelbild"] isEqualToString:@"Haus"]){
        myBild = [[NSString alloc] initWithString:@"Haus"];
        [wimmelArray addObject:[NSArray arrayWithObjects:@"70.0",@"-26",@"36.0", nil]]; //offset,scaling
        [wimmelArray addObject:[NSArray arrayWithObjects:@"01.0",@"04.5", nil]]; //1
        [wimmelArray addObject:[NSArray arrayWithObjects:@"08.3",@"03.7", nil]]; //2
        [wimmelArray addObject:[NSArray arrayWithObjects:@"11.0",@"02.2", nil]]; //3
        [wimmelArray addObject:[NSArray arrayWithObjects:@"00.0",@"05.5", nil]]; //4
        [wimmelArray addObject:[NSArray arrayWithObjects:@"12.5",@"06.8", nil]]; //5
        [wimmelArray addObject:[NSArray arrayWithObjects:@"00.0",@"09.5", nil]]; //6
        [wimmelArray addObject:[NSArray arrayWithObjects:@"09.7",@"09.5", nil]]; //7
        [wimmelArray addObject:[NSArray arrayWithObjects:@"13.4",@"09.3", nil]]; //8
        [wimmelArray addObject:[NSArray arrayWithObjects:@"00.0",@"13.5", nil]]; //9
        [wimmelArray addObject:[NSArray arrayWithObjects:@"05.5",@"16.0", nil]]; //10
        [wimmelArray addObject:[NSArray arrayWithObjects:@"09.7",@"14.0", nil]]; //11
        [wimmelArray addObject:[NSArray arrayWithObjects:@"10.5",@"16.0", nil]]; //12
        [wimmelArray addObject:[NSArray arrayWithObjects:@"12.5",@"14.0", nil]]; //13
        [wimmelArray addObject:[NSArray arrayWithObjects:@"01.0",@"17.0", nil]]; //14
        [wimmelArray addObject:[NSArray arrayWithObjects:@"04.0",@"17.8", nil]]; //15
        [wimmelArray addObject:[NSArray arrayWithObjects:@"10.5",@"17.7", nil]]; //16
        [wimmelArray addObject:[NSArray arrayWithObjects:@"02.3",@"19.7", nil]]; //17
        img = [[UIImage imageNamed:@"unserhaus.jpg"] retain];
    } 
    
    if([[myArray objectForKey:@"wimmelbild"] isEqualToString:@"Familie"]){
        myBild = [[NSString alloc] initWithString:@"Familie"];
        [wimmelArray addObject:[NSArray arrayWithObjects:@"00.0",@"-35",@"37.0", nil]]; //offset,scaling
        [wimmelArray addObject:[NSArray arrayWithObjects:@"00.0",@"04.5", nil]]; //1
        [wimmelArray addObject:[NSArray arrayWithObjects:@"03.0",@"01.5", nil]]; //2
        [wimmelArray addObject:[NSArray arrayWithObjects:@"08.2",@"01.0", nil]]; //3
        [wimmelArray addObject:[NSArray arrayWithObjects:@"05.8",@"04.5", nil]]; //4
        [wimmelArray addObject:[NSArray arrayWithObjects:@"11.0",@"02.0", nil]]; //5
        [wimmelArray addObject:[NSArray arrayWithObjects:@"13.0",@"01.5", nil]]; //6
        [wimmelArray addObject:[NSArray arrayWithObjects:@"05.0",@"07.2", nil]]; //7
        [wimmelArray addObject:[NSArray arrayWithObjects:@"08.0",@"09.6", nil]]; //8
        [wimmelArray addObject:[NSArray arrayWithObjects:@"02.0",@"12.5", nil]]; //9
        [wimmelArray addObject:[NSArray arrayWithObjects:@"03.2",@"16.4", nil]]; //10
        [wimmelArray addObject:[NSArray arrayWithObjects:@"01.0",@"20.0", nil]]; //11
        [wimmelArray addObject:[NSArray arrayWithObjects:@"07.5",@"20.0", nil]]; //12
        [wimmelArray addObject:[NSArray arrayWithObjects:@"10.0",@"19.5", nil]]; //13
        [wimmelArray addObject:[NSArray arrayWithObjects:@"13.0",@"19.5", nil]]; //14
        img = [[UIImage imageNamed:@"familie.jpg"] retain];
    } 

    if([[myArray objectForKey:@"wimmelbild"] isEqualToString:@"Groß und klein 1"]){
        myBild = [[NSString alloc] initWithString:@"Groß und klein 1"];
        [wimmelArray addObject:[NSArray arrayWithObjects:@"-25",@"-25",@"1.0", nil]]; //offset,scaling
        [wimmelArray addObject:[NSArray arrayWithObjects:@"180",@"50", nil]]; //1
        [wimmelArray addObject:[NSArray arrayWithObjects:@"60",@"232", nil]]; //2
        [wimmelArray addObject:[NSArray arrayWithObjects:@"376",@"50", nil]]; //3
        [wimmelArray addObject:[NSArray arrayWithObjects:@"261",@"223", nil]]; //4
        [wimmelArray addObject:[NSArray arrayWithObjects:@"572",@"60", nil]]; //5
        [wimmelArray addObject:[NSArray arrayWithObjects:@"455",@"232", nil]]; //6
        [wimmelArray addObject:[NSArray arrayWithObjects:@"176",@"292", nil]]; //7
        [wimmelArray addObject:[NSArray arrayWithObjects:@"122",@"483", nil]]; //8
        [wimmelArray addObject:[NSArray arrayWithObjects:@"254",@"307", nil]]; //10 
        [wimmelArray addObject:[NSArray arrayWithObjects:@"366",@"466", nil]]; //9
        [wimmelArray addObject:[NSArray arrayWithObjects:@"526",@"498", nil]]; //12
        [wimmelArray addObject:[NSArray arrayWithObjects:@"576",@"300", nil]]; //11
        [wimmelArray addObject:[NSArray arrayWithObjects:@"181",@"562", nil]]; //13
        [wimmelArray addObject:[NSArray arrayWithObjects:@"55",@"718", nil]]; //14
        [wimmelArray addObject:[NSArray arrayWithObjects:@"266",@"546", nil]]; //15
        [wimmelArray addObject:[NSArray arrayWithObjects:@"364",@"723", nil]]; //16
        [wimmelArray addObject:[NSArray arrayWithObjects:@"461",@"553", nil]]; //17
        [wimmelArray addObject:[NSArray arrayWithObjects:@"461",@"730", nil]]; //18
        img = [[UIImage imageNamed:@"gegenteile1.jpg"] retain];
    } 

    if([[myArray objectForKey:@"wimmelbild"] isEqualToString:@"Groß und klein 2"]){
        myBild = [[NSString alloc] initWithString:@"Groß und klein 2"];
        [wimmelArray addObject:[NSArray arrayWithObjects:@"-25",@"-25",@"1.0", nil]]; //offset,scaling
        [wimmelArray addObject:[NSArray arrayWithObjects:@"190",@"36", nil]]; //1
        [wimmelArray addObject:[NSArray arrayWithObjects:@"62",@"229", nil]]; //2
        [wimmelArray addObject:[NSArray arrayWithObjects:@"263",@"62", nil]]; //3
        [wimmelArray addObject:[NSArray arrayWithObjects:@"372",@"223", nil]]; //4
        [wimmelArray addObject:[NSArray arrayWithObjects:@"452",@"32", nil]]; //5
        [wimmelArray addObject:[NSArray arrayWithObjects:@"574",@"222", nil]]; //6
        [wimmelArray addObject:[NSArray arrayWithObjects:@"160",@"280", nil]]; //7
        [wimmelArray addObject:[NSArray arrayWithObjects:@"74",@"472", nil]]; //8
        [wimmelArray addObject:[NSArray arrayWithObjects:@"400",@"284", nil]]; //9
        [wimmelArray addObject:[NSArray arrayWithObjects:@"353",@"460", nil]]; //10
        [wimmelArray addObject:[NSArray arrayWithObjects:@"534",@"290", nil]]; //11
        [wimmelArray addObject:[NSArray arrayWithObjects:@"590",@"412", nil]]; //12
        [wimmelArray addObject:[NSArray arrayWithObjects:@"180",@"557", nil]]; //13
        [wimmelArray addObject:[NSArray arrayWithObjects:@"66",@"715", nil]]; //14
        [wimmelArray addObject:[NSArray arrayWithObjects:@"266",@"547", nil]]; //15
        [wimmelArray addObject:[NSArray arrayWithObjects:@"364",@"723", nil]]; //16
        [wimmelArray addObject:[NSArray arrayWithObjects:@"582",@"556", nil]]; //17
        [wimmelArray addObject:[NSArray arrayWithObjects:@"455",@"722", nil]]; //18
        img = [[UIImage imageNamed:@"gegenteile2.jpg"] retain];
    } 
    
    if([[myArray objectForKey:@"wimmelbild"] isEqualToString:@"Park 1"]){
        myBild = [[NSString alloc] initWithString:@"Park 1"];
        [wimmelArray addObject:[NSArray arrayWithObjects:@"-25",@"-25",@"1.0", nil]]; //offset,scaling
        [wimmelArray addObject:[NSArray arrayWithObjects:@"200",@"210", nil]]; //1
        [wimmelArray addObject:[NSArray arrayWithObjects:@"434",@"105", nil]]; //2
        [wimmelArray addObject:[NSArray arrayWithObjects:@"571",@"222", nil]]; //3
        [wimmelArray addObject:[NSArray arrayWithObjects:@"96",@"425", nil]]; //4
        [wimmelArray addObject:[NSArray arrayWithObjects:@"353",@"371", nil]]; //5
        [wimmelArray addObject:[NSArray arrayWithObjects:@"480",@"333", nil]]; //6
        [wimmelArray addObject:[NSArray arrayWithObjects:@"590",@"540", nil]]; //7
        [wimmelArray addObject:[NSArray arrayWithObjects:@"258",@"720", nil]]; //8
        img = [[UIImage imageNamed:@"wosindsie1.jpg"] retain];
    } 
    if([[myArray objectForKey:@"wimmelbild"] isEqualToString:@"Park 2"]){
        myBild = [[NSString alloc] initWithString:@"Park 2"];
        [wimmelArray addObject:[NSArray arrayWithObjects:@"-25",@"-25",@"1.0", nil]]; //offset,scaling
        [wimmelArray addObject:[NSArray arrayWithObjects:@"172",@"127", nil]]; //1
        [wimmelArray addObject:[NSArray arrayWithObjects:@"253",@"127", nil]]; //2
        [wimmelArray addObject:[NSArray arrayWithObjects:@"369",@"127", nil]]; //3
        [wimmelArray addObject:[NSArray arrayWithObjects:@"500",@"155", nil]]; //4
        [wimmelArray addObject:[NSArray arrayWithObjects:@"57",@"420", nil]]; //5
        [wimmelArray addObject:[NSArray arrayWithObjects:@"241",@"316", nil]]; //6
        [wimmelArray addObject:[NSArray arrayWithObjects:@"431",@"413", nil]]; //7
        [wimmelArray addObject:[NSArray arrayWithObjects:@"350",@"492", nil]]; //8
        [wimmelArray addObject:[NSArray arrayWithObjects:@"564",@"517", nil]]; //9
        [wimmelArray addObject:[NSArray arrayWithObjects:@"335",@"614", nil]]; //10
        img = [[UIImage imageNamed:@"wosindsie2.jpg"] retain];
    } 
    if([[myArray objectForKey:@"wimmelbild"] isEqualToString:@"Klassenzimmer"]){
        myBild = [[NSString alloc] initWithString:@"Klassenzimmer"];
        [wimmelArray addObject:[NSArray arrayWithObjects:@"-25",@"-25",@"1.0", nil]]; //offset,scaling
        [wimmelArray addObject:[NSArray arrayWithObjects:@"134",@"110", nil]]; //1
        [wimmelArray addObject:[NSArray arrayWithObjects:@"234",@"221", nil]]; //2
        [wimmelArray addObject:[NSArray arrayWithObjects:@"359",@"187", nil]]; //3
        [wimmelArray addObject:[NSArray arrayWithObjects:@"233",@"379", nil]]; //4
        [wimmelArray addObject:[NSArray arrayWithObjects:@"369",@"311", nil]]; //5
        [wimmelArray addObject:[NSArray arrayWithObjects:@"551",@"311", nil]]; //6
        [wimmelArray addObject:[NSArray arrayWithObjects:@"196",@"432", nil]]; //7
        [wimmelArray addObject:[NSArray arrayWithObjects:@"146",@"654", nil]]; //8
        [wimmelArray addObject:[NSArray arrayWithObjects:@"379",@"560", nil]]; //9
        [wimmelArray addObject:[NSArray arrayWithObjects:@"430",@"535", nil]]; //10
        [wimmelArray addObject:[NSArray arrayWithObjects:@"442",@"643", nil]]; //11
        img = [[UIImage imageNamed:@"wasdutunkannst1a.jpg"] retain];
    } 
    if([[myArray objectForKey:@"wimmelbild"] isEqualToString:@"Schulhof"]){
        myBild = [[NSString alloc] initWithString:@"Schulhof"];
        [wimmelArray addObject:[NSArray arrayWithObjects:@"-25",@"-25",@"1.0", nil]]; //offset,scaling
        [wimmelArray addObject:[NSArray arrayWithObjects:@"92",@"54", nil]]; //1
        [wimmelArray addObject:[NSArray arrayWithObjects:@"89",@"213", nil]]; //2
        [wimmelArray addObject:[NSArray arrayWithObjects:@"303",@"50", nil]]; //3
        [wimmelArray addObject:[NSArray arrayWithObjects:@"547",@"95", nil]]; //4
        [wimmelArray addObject:[NSArray arrayWithObjects:@"90",@"335", nil]]; //5
        [wimmelArray addObject:[NSArray arrayWithObjects:@"295",@"234", nil]]; //6
        [wimmelArray addObject:[NSArray arrayWithObjects:@"362",@"323", nil]]; //7
        [wimmelArray addObject:[NSArray arrayWithObjects:@"451",@"269", nil]]; //8
        [wimmelArray addObject:[NSArray arrayWithObjects:@"584",@"310", nil]]; //9
        [wimmelArray addObject:[NSArray arrayWithObjects:@"252",@"441", nil]]; //10
        [wimmelArray addObject:[NSArray arrayWithObjects:@"91",@"545", nil]]; //11
        [wimmelArray addObject:[NSArray arrayWithObjects:@"264",@"733", nil]]; //12
        [wimmelArray addObject:[NSArray arrayWithObjects:@"465",@"505", nil]]; //13
        [wimmelArray addObject:[NSArray arrayWithObjects:@"585",@"614", nil]]; //14
        img = [[UIImage imageNamed:@"wasdutunkannst1b.jpg"] retain];
    } 
    if([[myArray objectForKey:@"wimmelbild"] isEqualToString:@"Theater"]){
        myBild = [[NSString alloc] initWithString:@"Theater"];
        [wimmelArray addObject:[NSArray arrayWithObjects:@"-25",@"-25",@"1.0", nil]]; //offset,scaling
        [wimmelArray addObject:[NSArray arrayWithObjects:@"91",@"179", nil]]; //1
        [wimmelArray addObject:[NSArray arrayWithObjects:@"239",@"111", nil]]; //2
        [wimmelArray addObject:[NSArray arrayWithObjects:@"296",@"209", nil]]; //3
        [wimmelArray addObject:[NSArray arrayWithObjects:@"500",@"216", nil]]; //4
        [wimmelArray addObject:[NSArray arrayWithObjects:@"441",@"303", nil]]; //5
        [wimmelArray addObject:[NSArray arrayWithObjects:@"399",@"376", nil]]; //6
        [wimmelArray addObject:[NSArray arrayWithObjects:@"492",@"386", nil]]; //7
        [wimmelArray addObject:[NSArray arrayWithObjects:@"86",@"565", nil]]; //8
        [wimmelArray addObject:[NSArray arrayWithObjects:@"236",@"630", nil]]; //9
        [wimmelArray addObject:[NSArray arrayWithObjects:@"467",@"734", nil]]; //10
        img = [[UIImage imageNamed:@"wasdutunkannst2a.jpg"] retain];
    } 
    if([[myArray objectForKey:@"wimmelbild"] isEqualToString:@"Turnhalle"]){
        myBild = [[NSString alloc] initWithString:@"Turnhalle"];
        [wimmelArray addObject:[NSArray arrayWithObjects:@"-25",@"-25",@"1.0", nil]]; //offset,scaling
        [wimmelArray addObject:[NSArray arrayWithObjects:@"164",@"74", nil]]; //1
        [wimmelArray addObject:[NSArray arrayWithObjects:@"312",@"52", nil]]; //2
        [wimmelArray addObject:[NSArray arrayWithObjects:@"484",@"177", nil]]; //3
        [wimmelArray addObject:[NSArray arrayWithObjects:@"49",@"360", nil]]; //4
        [wimmelArray addObject:[NSArray arrayWithObjects:@"270",@"357", nil]]; //5
        [wimmelArray addObject:[NSArray arrayWithObjects:@"435",@"405", nil]]; //6
        [wimmelArray addObject:[NSArray arrayWithObjects:@"90",@"551", nil]]; //7
        [wimmelArray addObject:[NSArray arrayWithObjects:@"221",@"429", nil]]; //8
        [wimmelArray addObject:[NSArray arrayWithObjects:@"425",@"507", nil]]; //9
        [wimmelArray addObject:[NSArray arrayWithObjects:@"358",@"601", nil]]; //10
        [wimmelArray addObject:[NSArray arrayWithObjects:@"573",@"506", nil]]; //11
        [wimmelArray addObject:[NSArray arrayWithObjects:@"62",@"652", nil]]; //12
        [wimmelArray addObject:[NSArray arrayWithObjects:@"275",@"741", nil]]; //13
        [wimmelArray addObject:[NSArray arrayWithObjects:@"589",@"693", nil]]; //14
        img = [[UIImage imageNamed:@"wasdutunkannst2b.jpg"] retain];
    } 
    if([[myArray objectForKey:@"wimmelbild"] isEqualToString:@"Uhrzeit"]){
        myBild = [[NSString alloc] initWithString:@"Uhrzeit"];
        [wimmelArray addObject:[NSArray arrayWithObjects:@"-25",@"-25",@"1.0", nil]]; //offset,scaling
        [wimmelArray addObject:[NSArray arrayWithObjects:@"143",@"58", nil]]; //1
        [wimmelArray addObject:[NSArray arrayWithObjects:@"495",@"94", nil]]; //2
        [wimmelArray addObject:[NSArray arrayWithObjects:@"495",@"175", nil]]; //3
        [wimmelArray addObject:[NSArray arrayWithObjects:@"40",@"318", nil]]; //4
        [wimmelArray addObject:[NSArray arrayWithObjects:@"603",@"318", nil]]; //5
        [wimmelArray addObject:[NSArray arrayWithObjects:@"40",@"398", nil]]; //6
        [wimmelArray addObject:[NSArray arrayWithObjects:@"603",@"398", nil]]; //7
        [wimmelArray addObject:[NSArray arrayWithObjects:@"198",@"587", nil]]; //8
        [wimmelArray addObject:[NSArray arrayWithObjects:@"390",@"587", nil]]; //9
        [wimmelArray addObject:[NSArray arrayWithObjects:@"583",@"587", nil]]; //10
        [wimmelArray addObject:[NSArray arrayWithObjects:@"198",@"748", nil]]; //11
        [wimmelArray addObject:[NSArray arrayWithObjects:@"390",@"748", nil]]; //12
        [wimmelArray addObject:[NSArray arrayWithObjects:@"583",@"748", nil]]; //13
        img = [[UIImage imageNamed:@"wie_spaet_ist_es.jpg"] retain];
    } 
    if([[myArray objectForKey:@"wimmelbild"] isEqualToString:@"Tagesablauf"]){
        myBild = [[NSString alloc] initWithString:@"Tagesablauf"];
        [wimmelArray addObject:[NSArray arrayWithObjects:@"-25",@"-25",@"1.0", nil]]; //offset,scaling
        [wimmelArray addObject:[NSArray arrayWithObjects:@"40",@"34", nil]];   //1
        [wimmelArray addObject:[NSArray arrayWithObjects:@"151",@"177", nil]]; //2
        [wimmelArray addObject:[NSArray arrayWithObjects:@"296",@"47", nil]];  //3
        [wimmelArray addObject:[NSArray arrayWithObjects:@"558",@"52", nil]];  //4
        [wimmelArray addObject:[NSArray arrayWithObjects:@"48",@"260", nil]];  //5
        [wimmelArray addObject:[NSArray arrayWithObjects:@"37",@"463", nil]];  //6
        [wimmelArray addObject:[NSArray arrayWithObjects:@"259",@"251", nil]]; //7
        [wimmelArray addObject:[NSArray arrayWithObjects:@"343",@"512", nil]]; //8
        [wimmelArray addObject:[NSArray arrayWithObjects:@"453",@"300", nil]]; //9
        [wimmelArray addObject:[NSArray arrayWithObjects:@"558",@"392", nil]]; //10
        [wimmelArray addObject:[NSArray arrayWithObjects:@"468",@"401", nil]]; //11
        [wimmelArray addObject:[NSArray arrayWithObjects:@"42",@"538", nil]];  //12
        [wimmelArray addObject:[NSArray arrayWithObjects:@"119",@"601", nil]]; //13
        [wimmelArray addObject:[NSArray arrayWithObjects:@"230",@"524", nil]]; //14
        [wimmelArray addObject:[NSArray arrayWithObjects:@"332",@"738", nil]]; //15
        [wimmelArray addObject:[NSArray arrayWithObjects:@"577",@"613", nil]]; //16
        [wimmelArray addObject:[NSArray arrayWithObjects:@"507",@"713", nil]]; //17
        img = [[UIImage imageNamed:@"tagundnacht.jpg"] retain];
    } 
    if([[myArray objectForKey:@"wimmelbild"] isEqualToString:@"Wetter"]){
        myBild = [[NSString alloc] initWithString:@"Wetter"];
        [wimmelArray addObject:[NSArray arrayWithObjects:@"-25",@"-25",@"1.0", nil]]; //offset,scaling
        [wimmelArray addObject:[NSArray arrayWithObjects:@"66",@"72", nil]];   //1
        [wimmelArray addObject:[NSArray arrayWithObjects:@"149",@"200", nil]];  //2
        [wimmelArray addObject:[NSArray arrayWithObjects:@"65",@"315", nil]];  //3
        [wimmelArray addObject:[NSArray arrayWithObjects:@"245",@"155", nil]]; //4
        [wimmelArray addObject:[NSArray arrayWithObjects:@"372",@"41", nil]];  //5
        [wimmelArray addObject:[NSArray arrayWithObjects:@"375",@"129", nil]];  //6
        [wimmelArray addObject:[NSArray arrayWithObjects:@"556",@"48", nil]]; //7
        [wimmelArray addObject:[NSArray arrayWithObjects:@"503",@"266", nil]]; //8
        [wimmelArray addObject:[NSArray arrayWithObjects:@"432",@"315", nil]]; //9
        [wimmelArray addObject:[NSArray arrayWithObjects:@"315",@"377", nil]]; //10
        [wimmelArray addObject:[NSArray arrayWithObjects:@"319",@"480", nil]]; //11
        [wimmelArray addObject:[NSArray arrayWithObjects:@"405",@"463", nil]];  //12
        [wimmelArray addObject:[NSArray arrayWithObjects:@"545",@"432", nil]]; //13
        [wimmelArray addObject:[NSArray arrayWithObjects:@"57",@"449", nil]]; //14
        [wimmelArray addObject:[NSArray arrayWithObjects:@"188",@"509", nil]]; //15
        [wimmelArray addObject:[NSArray arrayWithObjects:@"28",@"568", nil]]; //16
        [wimmelArray addObject:[NSArray arrayWithObjects:@"248",@"562", nil]]; //17
        [wimmelArray addObject:[NSArray arrayWithObjects:@"217",@"680", nil]]; //18
        [wimmelArray addObject:[NSArray arrayWithObjects:@"426",@"696", nil]]; //19
        img = [[UIImage imageNamed:@"wetter.jpg"] retain];
    } 
    if([[myArray objectForKey:@"wimmelbild"] isEqualToString:@"Jahreszeiten links"]){
        myBild = [[NSString alloc] initWithString:@"Jahreszeiten links"];
        [wimmelArray addObject:[NSArray arrayWithObjects:@"-25",@"-25",@"1.0", nil]]; //offset,scaling
        [wimmelArray addObject:[NSArray arrayWithObjects:@"72",@"48", nil]];   //1
        [wimmelArray addObject:[NSArray arrayWithObjects:@"355",@"48", nil]];  //2
        [wimmelArray addObject:[NSArray arrayWithObjects:@"458",@"283", nil]];  //3
        [wimmelArray addObject:[NSArray arrayWithObjects:@"72",@"421", nil]]; //4
        [wimmelArray addObject:[NSArray arrayWithObjects:@"164",@"461", nil]];  //5
        [wimmelArray addObject:[NSArray arrayWithObjects:@"76",@"725", nil]];  //6
        [wimmelArray addObject:[NSArray arrayWithObjects:@"355",@"421", nil]]; //7
        [wimmelArray addObject:[NSArray arrayWithObjects:@"486",@"418", nil]]; //8
        [wimmelArray addObject:[NSArray arrayWithObjects:@"509",@"710", nil]]; //9
        img = [[UIImage imageNamed:@"jahreszeiten1.jpg"] retain];
    } 
    if([[myArray objectForKey:@"wimmelbild"] isEqualToString:@"Jahreszeiten rechts"]){
        myBild = [[NSString alloc] initWithString:@"Jahreszeiten rechts"];
        [wimmelArray addObject:[NSArray arrayWithObjects:@"-25",@"-25",@"1.0", nil]]; //offset,scaling
        [wimmelArray addObject:[NSArray arrayWithObjects:@"72",@"48", nil]];   //1
        [wimmelArray addObject:[NSArray arrayWithObjects:@"355",@"48", nil]];  //2
        [wimmelArray addObject:[NSArray arrayWithObjects:@"452",@"349", nil]]; //3
        [wimmelArray addObject:[NSArray arrayWithObjects:@"72",@"416", nil]];  //4
        [wimmelArray addObject:[NSArray arrayWithObjects:@"310",@"433", nil]]; //5
        [wimmelArray addObject:[NSArray arrayWithObjects:@"356",@"724", nil]];  //6
        img = [[UIImage imageNamed:@"jahreszeiten2.jpg"] retain];
    } 
    if([[myArray objectForKey:@"wimmelbild"] isEqualToString:@"Dreikoenigsfest"]){
        myBild = [[NSString alloc] initWithString:@"Dreikoenigsfest"];
        [wimmelArray addObject:[NSArray arrayWithObjects:@"-25",@"-25",@"1.0", nil]]; //offset,scaling
        [wimmelArray addObject:[NSArray arrayWithObjects:@"72",@"48", nil]];   //1
        [wimmelArray addObject:[NSArray arrayWithObjects:@"390",@"346", nil]];  //2
        [wimmelArray addObject:[NSArray arrayWithObjects:@"72",@"414", nil]]; //3
        img = [[UIImage imageNamed:@"jahreszeiten3.jpg"] retain];
    } 
    
    if([wimmelArray count] ==0){
        // err!
         myBild = [[NSString alloc] initWithString:@"Haus"];
        [wimmelArray addObject:[NSArray arrayWithObjects:@"70.0",@"-26",@"36.0", nil]]; //1
        [wimmelArray addObject:[NSArray arrayWithObjects:@"01.0",@"04.5", nil]]; //1
        img = [[UIImage imageNamed:@"unserhaus.jpg"] retain];
        myPoind = 1;
    }        
    
    // 2. setup the scrollview for one image and add it to the view controller
	//
    //____NGUYEN_HUY_SON
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 
    {
        [bigScrollView setBackgroundColor:[UIColor whiteColor]];
    }
    else
    {
        [bigScrollView setBackgroundColor:[UIColor blackColor]];
    }
    //___ENG_NGUYEN_HUY_SON
	
    bigScrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
    
    // if(imageView) [imageView release];
	imageView = [[UIImageView alloc] initWithImage:img];

    [bigScrollView setCanCancelContentTouches:NO];
    bigScrollView.clipsToBounds = YES;	// default is NO, we want to restrict drawing within our scrollview
    
   	[bigScrollView addSubview:imageView];
    [bigScrollView setContentSize:CGSizeMake(imageView.frame.size.width, imageView.frame.size.height)];
    ///_____dung de dat delegate cho Scrollview _____________________________________
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 
    {
        [bigScrollView setScrollEnabled: NO];
        [self SetUpDelegateTapInScrollView];
        imageView.userInteractionEnabled = YES;//dat che do bat su kien tap vao man hinh
        //dat Frame cho Scrollview ung voi xoay ngang va xoay doc
        bIsThemmenParrent = bIsThemmen;
        if ([self isPadPortrait] == TRUE) 
        {
            [navigationBar setHidden:FALSE];
            CGRect newFrame = CGRectMake(65, 138, 1024, 1024);
            bigScrollView.frame = newFrame;
            [[tabbarControllerRoot.view.subviews objectAtIndex:0] setFrame:CGRectMake(0, 0, 768, 1024)];
        }
        else//neu xoay ngang
        {
            [navigationBar setHidden:TRUE];//dat navigation de an di
            //frame cho xoay ngang
            [bigScrollView setFrame:CGRectMake(32, 0, 1024, 1024)] ;//dat frame
            [[tabbarControllerRoot.view.subviews objectAtIndex:0] setFrame:CGRectMake(0, 0, 1024, 768)];
        }
        NSLog(@"TAP THE SCREEN, SUBVIEWS: %@",self.view.subviews);
    }
    else
    {
        [bigScrollView setScrollEnabled: YES];
    }    

    // show poinds
    float xOffset = [[[wimmelArray objectAtIndex:0]objectAtIndex:0] floatValue];
    float yOffset = [[[wimmelArray objectAtIndex:0]objectAtIndex:1] floatValue];
    float multi   = [[[wimmelArray objectAtIndex:0]objectAtIndex:2] floatValue];
    
    

    for(int i=1; i<[wimmelArray count]; i++) {        
        float x = [[[wimmelArray objectAtIndex:i] objectAtIndex:0] floatValue] * multi + xOffset;
        float y = [[[wimmelArray objectAtIndex:i] objectAtIndex:1] floatValue] * multi + yOffset;

        
        UIButton *btnTwo = [UIButton buttonWithType:UIButtonTypeCustom]; 
        btnTwo.tag=i;
        btnTwo.frame = CGRectMake(x, y, 54, 53);
        UIImage *btnImage = [UIImage imageNamed:@"ibutton.png"];
        [btnTwo setImage:btnImage forState:UIControlStateNormal];
        [btnTwo addTarget:self action:@selector(clickPhase1:) forControlEvents:UIControlEventTouchUpInside];
        [bigScrollView addSubview:btnTwo];
        
        if(myPoind == i) newOffset = CGPointMake(x,y);
    }
    
    
    //__NGUYEN_HUY_SON__
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 
    { 
        xPoind = 0;
        yPoind = 0;
    }
    else
    {
        if(myPoind != 0){
            xPoind = xOffset + [[[wimmelArray objectAtIndex:myPoind] objectAtIndex:0] floatValue] * multi -100;
            yPoind = yOffset + [[[wimmelArray objectAtIndex:myPoind] objectAtIndex:1] floatValue] * multi -60;
            
            if(xPoind > 640/2) xPoind = 640/2;
            if(xPoind < 0) xPoind = 0;
            if(yPoind > 774/2) yPoind = 774/2;
            if(yPoind < 0) yPoind = 0;
        } else{
            xPoind = 0;
            yPoind = 0;
        }
        
    }
    //_____END_NGUYEN_HUY_SON
    CGPoint mPoind = CGPointMake(xPoind,yPoind);
    [bigScrollView  setContentOffset:mPoind animated:false];
    

    //bigScrollView.minimumZoomScale=0.5;     // default is 1.0
    //bigScrollView.maximumZoomScale=1.0;
	//[bigScrollView setZoomScale:bigScrollView.minimumZoomScale];
 
    // open Overlay...
    
    
    if(myPoind == 0){
        if([[myArray objectForKey:@"ton"] length]>0){
            myNumber = 0;
            [self playIt];
            if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
                bIsOverLay = FALSE;
            }
            
        }
    } else {
        //__NGUYEN_HUY_SON_IPAD_ONLY
        
        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 
        {
            myPoindInfo = [woerPre getPoindInfo:myBild num:myPoind];
            bIsOverLay = TRUE;
        }
        else
        {
            myPoindInfo = [(Lextra_Engine*)Delegate getPoindInfo:myBild num:myPoind];
        }
        [self clickAcktion1:myPoind];
        if ([self isPadPortrait] == TRUE) {
            bIsPortrait = TRUE;
        }
        else
        {
            bIsPortrait = FALSE;
        }
        OffsetGloble = CGPointMake(newOffset.x-xPoind+27,newOffset.y-yPoind+26);
        [self.wimmelOverlayViewController showInfo:myPoindInfo pos:OffsetGloble portrait:bIsPortrait];
    }
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 
    {
        if([self isPadPortrait] == TRUE)
        {
            wimmelOverlayViewController.view.frame = CGRectMake(0, 44, wimmelOverlayViewController.view.frame.size.width, wimmelOverlayViewController.view.frame.size.height);
        }
        else
        {
            wimmelOverlayViewController.view.frame = CGRectMake(0, 0, wimmelOverlayViewController.view.frame.size.width, wimmelOverlayViewController.view.frame.size.height);
        }
    }
}
-(void)clickPhase1:(id)sender {
    
    int tid = ((UIControl*)sender).tag;
    //___NGUYEN_HUY_SON__
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 
    {
        myPoindInfo = [woerPre getPoindInfo:myBild num:tid];        //[myLink release];
        bIsOverLay = TRUE;
    }
    else
    {
        myPoindInfo = [Delegate getPoindInfo:myBild num:tid];
    }
    //___END_NGUYEN_HUY_SON__
    [self clickAcktion1:tid];
    
    // show poinds
    CGPoint myOffset = [bigScrollView contentOffset];
    float xOffset = ((UIControl*)sender).center.x - myOffset.x;
    float yOffset = ((UIControl*)sender).center.y - myOffset.y;
    
    //CGPoint newOffset = CGPointMake(xOffset,yOffset);
    OffsetGloble = CGPointMake(xOffset,yOffset);
    
    if ([self isPadPortrait] == TRUE) {
        bIsPortrait = TRUE;
    }
    else
    {
        bIsPortrait = FALSE;
    }
    [self.wimmelOverlayViewController showInfo:myPoindInfo pos:OffsetGloble portrait:bIsPortrait];
}

-(void)clickAcktion1:(int)num {
    
    //NSDictionary *myPoindInfo = [Delegate getPoindInfo:myBild num:num];
    
    myNumber = num;
    
    [self playIt];
    
    self.wimmelOverlayViewController.view.hidden = false;
}





-(void)playIt{
    
    if(audioPlayer) [audioPlayer stop];
    //___NGUYEN_HUY_SON
    NSDictionary *myPoindInfo;
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 
    {
        myPoindInfo = [woerPre getPoindInfo:myBild num:myNumber]; 
    }
    else
    {
        myPoindInfo = [Delegate getPoindInfo:myBild num:myNumber];
    }    
    //__END_NGUYEN_HUY_SON__
    NSString *myFilename;
    NSString *myName = [myPoindInfo objectForKey:@"ton"];
    
    if([myName hasSuffix:@".mp3"]){
        myFilename = [myName substringToIndex:[myName length]-4];
    } else {
        myFilename = [[NSString alloc] initWithString:myName];
    }
    
    if(myName){
        NSURL *url = [[NSURL alloc] initFileURLWithPath:[[NSBundle mainBundle] pathForResource:myFilename ofType:@"m4a"]];
        if(audioPlayer) {
            [audioPlayer stop];
            [audioPlayer release];
        }
        audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
        audioPlayer.delegate = self;
        if(audioPlayer) [audioPlayer stop];
        [audioPlayer play];
        [url release];
    }
}

-(void)closePopup{
    
    self.wimmelOverlayViewController.view.hidden = true;
    if(audioPlayer) [audioPlayer stop];
}


- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
    return imageView;
    
}

/*
- (void)scrollViewDidZoom:(UIScrollView *)scrollView {
    imageView.frame = [self centeredFrameForScrollView:bigScrollView andUIView:imageView];
}

- (CGRect)centeredFrameForScrollView:(UIScrollView *)scroll andUIView:(UIView *)rView {
    CGSize boundsSize = scroll.bounds.size;
    CGRect frameToCenter = rView.frame;
    // center horizontally
    if (frameToCenter.size.width < boundsSize.width) {
        frameToCenter.origin.x = (boundsSize.width – frameToCenter.size.width) / 2;
    }
    else {
        frameToCenter.origin.x = 0;
    }
    // center vertically
    if (frameToCenter.size.height < boundsSize.height) {
        frameToCenter.origin.y = (boundsSize.height – frameToCenter.size.height) / 2;
    }
    else {
        frameToCenter.origin.y = 0;
    }
    return frameToCenter;
}
*/


- (IBAction) stop:(id)sender{
    
    if(audioPlayer) [audioPlayer stop];
 //   myButton1.hidden = false;
 //   myButton2.hidden = true;

}

- (void)audioPlayerDidFinishPlaying:IntroPlayer successfully: (BOOL)flag
{
    if(audioPlayer) [audioPlayer stop];
  //  myButton1.hidden = false;
  //  myButton2.hidden = true;
}
- (void)sstop{
    if(audioPlayer) [audioPlayer stop];
  //  myButton1.hidden = false;
  //  myButton2.hidden = true;
}


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    bIsPortrait = TRUE;
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)dealloc
{
    [tabbarControllerRoot.tabBar setHidden:FALSE];
    if( [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortrait ){
        [[tabbarControllerRoot.view.subviews objectAtIndex:0] setFrame:CGRectMake(0, 0, 768, 1024 - 49)];
    }
    else {
        [[tabbarControllerRoot.view.subviews objectAtIndex:0] setFrame:CGRectMake(0, 0, 1024, 719)];
    }
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    //__NGUYEN__HUY_SON
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 
    {
        [navigationBar setTintColor:[[UIColor alloc] initWithRed:20.0 / 255 green:59.0 / 255 blue:102.0 / 255 alpha:1.0]];
        CGFloat navBarHeight = 44.0f;    
        CGRect frame = CGRectMake(navigationBar.frame.origin.x, navigationBar.frame.origin.y, navigationBar.frame.size.width, navBarHeight);
        [navigationBar setFrame:frame];
    }  //___END_NGUYEN_HUY_SON
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    //__NGUYEN_HUY_SON__
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 
    {
        return YES;
    }
    else
    {
        return (interfaceOrientation == UIInterfaceOrientationPortrait);
    }
    //__END_NGUYEN_HUY_SON
}
//______NGUYEN_HUY_SON________________________________________________________________________________________________________________________
#pragma mark -
#pragma mark Managing the popover
//su kien nay xay ra truoc khi quay
- (void)showRootPopoverButtonItem:(UIBarButtonItem *)barButtonItem {
    [navigationBar.topItem setLeftBarButtonItem:barButtonItem animated:NO];

    bIsPortrait = TRUE;
    
    [navigationBar setHidden:FALSE];
    CGRect newFrame = CGRectMake(65, 138, 768, 1024);
    bigScrollView.frame = newFrame;//dat frame
    //[[tabbarControllerRoot.view.subviews objectAtIndex:0] setFrame:CGRectMake(0, 0, 1024, 768)];
    
    [tabbarControllerRoot.tabBar setHidden:FALSE];
    if (bIsOverLay == TRUE && myPoindInfo != nil) {
        wimmelOverlayViewController.view.frame = CGRectMake(0, 44, wimmelOverlayViewController.view.frame.size.width, wimmelOverlayViewController.view.frame.size.height);

        [self.wimmelOverlayViewController showInfo:myPoindInfo pos:OffsetGloble portrait:TRUE];
    }
    NSLog(@"__________View:  %@",self.view);
    NSLog(@"__________SubView:   %@",self.view.subviews);
}


- (void)invalidateRootPopoverButtonItem:(UIBarButtonItem *)barButtonItem {
    [navigationBar.topItem setLeftBarButtonItem:nil animated:NO];

    [navigationBar setHidden:TRUE];//dat navigation de an di
    CGRect newFrame = CGRectMake(32, 0, 768, 1024);

    bigScrollView.frame = newFrame;
    //[[tabbarControllerRoot.view.subviews objectAtIndex:0] setFrame:CGRectMake(0, 0, 768, 1024)];
    bIsPortrait = FALSE;
    if (bIsOverLay == TRUE && myPoindInfo != nil) {
        wimmelOverlayViewController.view.frame = CGRectMake(0, 0, wimmelOverlayViewController.view.frame.size.width, wimmelOverlayViewController.view.frame.size.height);
        [self.wimmelOverlayViewController showInfo:myPoindInfo pos:OffsetGloble portrait:FALSE];
    }
    NSLog(@"LANSCAPE____View:  %@",self.view);
    NSLog(@"LANSCAPE____SubView:   %@",self.view.subviews);
}


-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    bIsHideTabbar = !bIsHideTabbar;
    if ([self isPadLandscape] == TRUE) 
    {
        [tabbarControllerRoot.tabBar setHidden:bIsHideTabbar];
    }
}

-(void) SetUpDelegateTapInScrollView
{
    bigScrollView.delegate = self;
    // add gesture recognizers to the image view
    UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];//1 lan cham tay --> goi den ham handleSingleTap duoc dinh nghia ben duoi
    [imageView addGestureRecognizer:singleTap];
    [singleTap release];
}

#pragma mark TapDetectingImageViewDelegate methods
- (void)handleSingleTap:(UIGestureRecognizer *)gestureRecognizer {
    bIsHideTabbar = !bIsHideTabbar;
    if ([self isPadLandscape] == TRUE) 
    {
        [tabbarControllerRoot.tabBar setHidden:bIsHideTabbar];
    }
    NSLog(@"____Image ScrollView Tap");
}


//___END_NGUYEN_HUY_SON________________________________________________________________________________________

@end




